package cn.school.thoughtworks.section2;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class PracticeB {
    Map<String, Integer> countSameElements(List<String> collection1) {
        Map<String,Integer> SameElments=new HashMap<String,Integer>();
        for(int i=0;i<collection1.size();i++){
            if(collection1.get(i).length()>1){
                String[] str=collection1.get(i).split("-");
                SameElments.put(str[0],Integer.parseInt(str[str.length-1]));
            }else{
                Integer num = SameElments.get(collection1.get(i));
                if(num!=null){
                    SameElments.put(collection1.get(i),num+1);
                }else {
                    SameElments.put(collection1.get(i),1);
                }

            }

        }
        //实现练习要求，并改写该行代码。
        return SameElments;


    }
}